﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUS.ISS.ARS.BusinessEntity;
using NUS.ISS.ARS.Common;
using NUS.ISS.ARS.BusinessEntity.ViewModels;

namespace NUS.ISS.ARS.Service.Entity
{
    public class DataAdapter
    {
        public static FlightSchedule GetFlightScheduleFromFlightScheduleData(FlightScheduleData data)
        {
            try
            {
                if (data != null)
                {
                    return new FlightSchedule()
                    {
                        FlightScheduleId = data.FlightScheduleId,
                        FlightNumber = data.FlightNumber,
                        FromAirportId = data.FromAirportId,
                        ToAirportId = data.ToAirportId,
                        DepartureTime = data.DepartureTime,
                        ArrivalTime = data.ArrivalTime,
                        AdultFare = data.AdultFare,
                        ChildFare = data.ChildFare,
                        InfantFare = data.InfantFare,
                        AircraftId = data.AircraftId
                    };
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
        public static SaveResult GetSaveResultFromSaveResultData(SaveResultData data)
        {
            try
            {
                if (data != null)
                {
                    return new SaveResult()
                    {
                         Status=data.Status,
                           Message=data.Message
                    };
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
        public static ReservationViewObject GetReservationViewFromReservationViewData(ReservationViewData data)
        {
            try
            {
                if (data != null)
                {
                    var reservation= new ReservationViewObject()
                    {
                        FromCityId = data.FromCityId,
                        ToCityId = data.ToCityId,
                        DepartDate = data.DepartDate,
                        IsRoundTrip = data.IsRoundTrip,
                        NumOfAdult = data.NumOfAdult,
                        NumOfChild = data.NumOfChild,
                        ReturnDate = data.ReturnDate,
                        TotalDue = data.TotalDue
                    };

                    if (data.Passengers != null)
                    {
                        foreach (var p in data.Passengers)
                        {
                            reservation.Passengers.Add(DataAdapter.GetPassengerFromPassengerData(p));
                        }
                    }

                    if (data.SelectedBookingTrips != null)
                    {
                        foreach (var t in data.SelectedBookingTrips)
                        {
                            reservation.SelectedBookingTrips.Add(DataAdapter.GetFlightBookingTripViewDataFromFlightBookingTripViewDataData(t));
                        }
                    }

                    reservation.Contact = DataAdapter.GetCustomerFromCustomerData(data.Contact);

                    return reservation;
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
        public static Customer GetCustomerFromCustomerData(CustomerData data)
        {
            try
            {
                if (data != null)
                {
                    return new Customer()
                    {
                         ContactNumber=data.ContactNumber,
                          Email=data.Email,
                           FirstName=data.FirstName,
                            LastName=data.LastName,
                             Gender=data.Gender
                    };
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
        public static Passenger GetPassengerFromPassengerData(PassengerData data)
        {
            try
            {
                if (data != null)
                {
                    return new Passenger()
                    {
                        PassportNumber = data.PassportNumber,
                        FirstName = data.FirstName,
                        LastName = data.LastName,
                        Gender = data.Gender,
                        CountryId = data.CountryId,
                        DateOfBirth = data.DateOfBirth,
                        ExpiryDate = data.ExpiryDate

                    };
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
        public static FlightBookingTripView GetFlightBookingTripViewDataFromFlightBookingTripViewDataData(FlightBookingTripViewData data)
        {
            try
            {
                if (data != null)
                {
                    return new FlightBookingTripView()
                    {
                         DepartureCityCode=data.DepartureCityCode,
                         ArrivalCityCode=data.ArrivalCityCode,
                         ArrivalTime=data.ArrivalTime,
                          FlightDate=data.FlightDate,
                          FlightNo=data.FlightNo,
                           DepartureTime=data.DepartureTime,
                            FromAirportName=data.FromAirportName,
                             FromCity=data.FromCity,
                              ToCity=data.ToCity,
                               TotalPrice=data.TotalPrice,
                                TotalAdultPrice=data.TotalAdultPrice,
                                TotalChildPrice=data.TotalChildPrice,
                                FlightScheduleId = data.FlightScheduleId

                    };
                }
            }
            catch (Exception ex)
            {
                //Log Exception
            }

            return null;
        }
    }
}
